package com.pro_one.job;

import com.pro_one.constant.RedisConstant;
import com.pro_one.util.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Date;
import java.util.Set;

public class ClearImgJobs {
    @Autowired
    private JedisPool jedisPool;

    public void clearImg() {
        Set<String> imgs4Clear = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (imgs4Clear != null) {
            for (String imgName : imgs4Clear) {
                QiniuUtils.deleteFileFromQiniu(imgName);
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, imgName);
                System.out.println("imgName4Clear : " + imgName);
            }
        }
        System.out.println("excute..." + new Date());
        System.out.println("========================================================================================>");

    }
}
